<?php 

session_start();
if (!isset($_SESSION['id'])) {
	//WHAT TO DISPLAY IF NOT LOGGED IN
	?>
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	
	<head>
	</head>
	<body>
<a href="login-facebook.php">Click here to login through facebook and see our awesome site</a>
	</body>
	</html>
	<?php 
} else {
	
	//SESSION IS THERE
//Sets the challenge
$challenge_id = "1";
?>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
	<?php include 'includes/head.php' ?>
	<link href="css/custom.css" rel="stylesheet" type="text/css" />
    <script language="javascript" src="js/battle.js"></script>
    <link rel="stylesheet" type="text/css" href="lightbox/lightbox.css" media="screen" />  
    <link rel="stylesheet" type="text/css" href="comment/css/style.css"  />
	    <link rel="stylesheet" type="text/css" href="jqforms/script.js"  />
    <link rel="stylesheet" type="text/css" href="jqforms/style.css"  />

    <script type="text/javascript" src="lightbox/jquery.lightbox-0.5.js"></script>
    <script type="text/javascript">
			var challenge_id_var = <?php echo $challenge_id; ?>;
    </script>
    <script type="text/javascript" src="comment/js/comments.actions.js"></script>

	<script type="text/javascript">
    $(function() {
        $('.battle_item a').lightBox();
			$('.main-content').jqTransform({imgPath:'jqforms/img/'});
    });
    </script>
    
    
    
    <script type="text/javascript">
		function GetPaginationPage(array1,i) {
			
			$(function() {
        $('.contestants_list').children().addClass('hidden');
			
    });
	
	if ($('.contestants_list').children().hasClass('.'+i)) {
		$('.'+i).removeClass('hidden');
		
	}
			
	else {		
			
		$.ajax({
			type: "POST",
			url: "includes/get_pagination_page.php",
			data: {data : array1,id:i},
			success: (function(data2){ 
			$('.contestants_list').append(data2);
			   $(function() {
        $('.battle_item .preview').lightBox();
			$('.main-content').jqTransform({imgPath:'jqforms/img/'});
			imagePreview();
    });
			}),
			});
			
	}
	};
		
	</script>
    
    <?php 
	//Get all the id's of the contestant who are in challenge $challenge_id
	$query = mysql_query("SELECT * FROM splash_contestants WHERE splash_contestant_challenge_id = '$challenge_id'");
	$contestants_array = array();
	while($result = mysql_fetch_array($query)){
		$contestants_array[]=$result['id'];
	}
	
	
		  $contestant_groups = (array_chunk($contestants_array, 2));
		
	?>
    <script>
		//GetPaginationPage("<?php echo base64_encode(serialize($contestants_array)); ?>");  
	</script>
    
    
    
</head>

<body class="view_challenge">
<!-- LOGOUT LINK -->
<a href="logout.php?logout">Logout</a>



<div id="fb-root"></div>
<script>
    (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</script>


<div id="wrapper">

            <?php 
			//Get contest info 
				$sqlquery=mysql_query("SELECT * FROM splash_challenges WHERE id = '$challenge_id'");
				if (!$result) {
					 header("location: $home");
				}
				while($row = mysql_fetch_assoc($sqlquery)) {
					$title = $row['title'];
					$description = $row['description'];
				}
			?>
            
            	<div>
                    <div class="main-title">
                        <h2>
                        	<span><?php echo $title ?></span>
                            <br class="cleft" />
                        </h2>
                    </div>
                    <div class="main-content">
                        <form class="" name="" id="" method="POST" action="vote_process.php">
                        <input type="hidden" name="challenge_id"  value="<?php echo $challenge_id ?>" /> 
                            <div class="block-left battlepage_container">
                            <ul>
							<? for($i=0;$i<count($contestant_groups);$i++){?>
								<li>
                                <a href="#" onClick="GetPaginationPage('<? 
								$contestant_get[] = array();
                                foreach ($contestant_groups as $key=>$split) {
									if($key==$i){
									echo base64_encode(serialize($split));
									}
								}
										?>','<?=$i;?>');"><?=$i;?></a>
                                </li>
								 <?
                                 }
								 ?>
                                 
                                 </ul>
                                <ul class="contestants_list">
                                   
                                   
                                </ul>
                                 <div class="block-right submit">
                             <input type="submit" id="submit"  value=""><br /><br />
                             </div>

                                                                
                            </div>
                            
                    </form>
                     <!--Comments-->
                                <div>
                                    <table id="displayComment" class="gridtable commentTable">
                                	
                                    </table>
                                </div>
                                
                             <div style="background-color:#000000;">
                              <form action="join_contest_process.php" id="contestant_form" method="post" enctype="multipart/form-data">
                            <div class="block-left battlepage_container">
                                <div class="desc">
                                    <p class="tips">Better images mean more votes. Make it a good image.</p>
                                </div>
                                <div class="upload">
                                	<input type="file" name="file" id="file" />
									Description:<textarea name="description">200 characters or less!</textarea>
                                    <input type="hidden" name="challenge_id"  value="<?php echo $challenge_id ?>" /> 
                                </div>
                            </div>
                            <div class="block-right submit">
                                <input type="submit" id="submit"  value=""><br /><br />
                            </div>
                        </form>
                        </div>
                             
                	</div>   
            </td>
        	<!--<td id="col-right"></td>-->
        </tr>
    </table>
    
    <style>

    .popup{
        
       
        
        

    }
</style>

    
    
</div>

<div id="bottom">
</div>

</body>

</html>

<?php } ?>
